/**
 * 
 */
package com.googlecode.gwtresume.client.widgets;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.Widget;

public class DefinitionList extends ComplexPanel {

	public DefinitionList() {
		setElement(DOM.createElement("dl"));
	}

	public DefinitionList(String style) {
		this();
		setStylePrimaryName(style);
	}
	
	public void add(Widget w) {

		super.add(w, getElement());
	}

	public void add(String value, String definition) {
		add(new Item(true, value));
		add(new Item(false, new InlineHTML(definition)));
	}
	
	public void insert(Widget w, int beforeIndex) {
		super.insert(w, getElement(), beforeIndex, true);
	}
	
	public static class Item extends ComplexPanel implements HasText {
		
		
		public Item(boolean t) {
			setElement(DOM.createElement(t ? "dt" : "dd"));
		}
		
		public Item(boolean t, String title) {
			this(t);
			setText(title);
		}		
		
		public Item(boolean t, Widget widget) {
			this(t);
			add(widget);
		}


		public Item(boolean t, String style, String title) {
			this(t);
			setStylePrimaryName(style);
			setText(title);
		}

		public Item(boolean t, String style, Widget widget) {
			this(t);
			setStylePrimaryName(style);
			add(widget);
		}

		public void add(Widget w) {
			super.add(w, getElement());
		}

		public void insert(Widget w, int beforeIndex) {
			super.insert(w, getElement(), beforeIndex, true);
		}

		public String getText() {
			return DOM.getInnerText(getElement());
		}

		public void setText(String text) {
			DOM.setInnerText(getElement(), (text == null) ? "" : text);
		}
		
		

	}
	
	
	
}